require 'spec_helper'
require 'game_object'

describe GameObject, "creation" do
  before(:each) do
    @obj = GameObject.new
  end
  
  it "should have a position in space on creation" do
    @obj.position.to_a.should == [0, 0]
  end
  
  it "should be possible to create an object at any point in space" do
    @obj = GameObject.new([10, 43])
    @obj.position.to_a.should == [10, 43]
  end
  
  it "should load from a YAML file" do
    @obj = GameObject.load("example_object")
    @obj.game_type.should == :example_object
    @obj.width.should == 20
    @obj.height.should == 20
    @obj.thrust.should == 5
    @obj.max_speed.should == 10
  end
  
  it "should respond to #update with game state" do
    @obj.should respond_to(:update)
  end
  
  it "should respond to #height and #width" do
    @obj.should respond_to(:width)
    @obj.should respond_to(:height)
  end
  
  it "should not allow height or width < 0" do
    should_throw = [ -10, -5, -20 ]
    should_not_throw = [ 0, 10, 5, 200 ]
    
    should_throw.each do |v|
      lambda { @obj.width = v }.should throw_symbol(:out_of_range)
      lambda { @obj.height = v }.should throw_symbol(:out_of_range)
    end
    
    should_not_throw.each do |v|
      lambda { @obj.width = v }.should_not throw_symbol(:out_of_range)
      lambda { @obj.height = v }.should_not throw_symbol(:out_of_range)
    end
  end
end